﻿using System;
using RIBA.DomainServices;
using Riba.MVVMSL;

namespace Admin
{
	public class AdminPage1_VM : ViewModelBase
	{
		public IDomainServiceRIBA _domainService;

		private string _serverTime = "";
		public string ServerTime
		{
			get { return _serverTime; }
			set { SetPropertyValue(ref _serverTime, value, () => ServerTime); }
		}

		public AdminPage1_VM()
		{
			if (IsInDesignToolNonStatic)
				_domainService = new DomainServiceRIBAMock();
			else
				_domainService = new DomainServiceRIBALive();

			_domainService.GetServerTime("1", GetServerTime_Callback);
		}

		//For dependency injection
		public AdminPage1_VM(IDomainServiceRIBA domainService)
		{
			_domainService = domainService;
			_domainService.GetServerTime("1", GetServerTime_Callback);
		}

		private void GetServerTime_Callback(string time, Exception exception)
		{
			if (exception != null)
			{
				RaiseShowMsgBox(new ShowMsgBoxEventArgs(exception.Message, "GetServerTime_Callback"));
				return;
			}

			ServerTime = string.Format("Server-Zeit= {0}", time);
		}
	}
}
